package com.tuling.stu.util;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class TlUtil {

	/**
	 * 多线程测试方法
	 * 
	 * @param nThreads
	 *            - 线程个数
	 * @param singleNum
	 *            - 单个线程执行次数
	 * @param thread
	 *            - 线程
	 */
	public static void timeTasks(int nThreads, int singleNum, Thread thread) {
		ExecutorService pool = Executors.newFixedThreadPool(nThreads);

		for (int i = 0; i < nThreads; i++) {
			for (int j = 0; j < singleNum; j++) {
				pool.execute(thread);
			}
		}
	}

	/**
	 * 多线程测试方法
	 * 
	 * @param nThreads
	 *            - 线程个数
	 * @param singleNum
	 *            - 单个线程执行次数
	 * @param thread
	 *            - 线程
	 */
	public static void timeTasks(int nThreads, int singleNum, Runnable runnable) {
		ExecutorService pool = Executors.newFixedThreadPool(nThreads);

		for (int i = 0; i < nThreads; i++) {
			for (int j = 0; j < singleNum; j++) {
				pool.execute(runnable);
			}
		}

	}

}
